package bomberman.model;

import java.awt.Graphics;

import bomberman.MainGame;
import bomberman.swing.BomJPanel;
import bomberman.util.GameMap;

public class Wall {
	private int x;
	private int y;

	public Wall(int x, int y){
		this.x = x;
		this.y = y;
	}
	
	
	/**
	 * 根据坐标从list中查找wall对象
	 */
	public static Wall findWallByXY(int x, int y){
		for(Wall r : BomJPanel.walls){
			if(x == r.getX() && y == r.getY()){
				return r;
			}
		}
		return null;
	}
	
	
	/**
	 * 砖被爆炸，移除
	 */
	public void removeWall(){
		// 从集合中移除，避免继续画
		BomJPanel.walls.remove(this);
		
		// 在数组中修改，避免碰撞
		GameMap.map[y/30][x/30] = GameMap.ele_blank;

		// 开启线程控制砖的爆炸效果
		new Boom(x, y).addBoom();
	}
	
	
	public void draw(Graphics g) {
		g.drawImage(GameMap.img_wall, x, y, MainGame.jPanelIndex);
	}
	
	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}
}
